package com.example.androidcoursedesing.main.adapter;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.example.androidcoursedesing.R;
import com.example.androidcoursedesing.main.bean.SolarTermResponse;

import java.util.List;

public class SolarTermAdapter  extends RecyclerView.Adapter<SolarTermAdapter.SolarTerViewHolder> {
    private Context mContext;
    private LayoutInflater inflater;

    private List<SolarTermResponse.ListBean> data;


    public SolarTermAdapter(Context context){
        this.mContext=context;
        inflater= LayoutInflater.from(mContext);

    }

    public void setData(List<SolarTermResponse.ListBean> list) {
        this.data = list;
    }

    @NonNull
    @Override
    public SolarTerViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = inflater.inflate(R.layout.item_layout, parent, false);
        SolarTerViewHolder solarTerViewHolder = new SolarTerViewHolder(view);
        return solarTerViewHolder;
    }

    @Override
    public void onBindViewHolder(@NonNull SolarTerViewHolder holder, int position) {
        SolarTermResponse.ListBean listBean = data.get(position);
        Log.i("SolarTermAdapter",listBean.getTitle());
        holder.title_tv.setText(listBean.getTitle());
        holder.content_tv.setText(listBean.getContent());
        //holder.item_imageview
        // this：上下文   url：要加载的图片链接   imageView: 要显示的图片控件
       // Glide.with(this).load(url).into(imageView);
        Glide.with(mContext).load(listBean.getUrl()).into(holder.item_imageview);



    }

    @Override
    public int getItemCount() {
        return data.size();
    }

    class  SolarTerViewHolder extends  RecyclerView.ViewHolder{
      private ImageView item_imageview;
      private TextView title_tv;
      private TextView content_tv;

        public SolarTerViewHolder(@NonNull View itemView) {
            super(itemView);
            item_imageview=itemView.findViewById(R.id.item_imageview);
            title_tv=itemView.findViewById(R.id.title_tv);
            content_tv= itemView.findViewById(R.id.content_tv);
        }
    }
}
